package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2023/4/29 - 04 - 29 - 17:57
 * @Description: com.sky.controller.admin
 * @version: 1.0
 */
/**
 * 菜品管理
 */
@RestController("adminDishController")
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;
    /**
     * 新增菜品
     *
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO){
        return dishService.save(dishDTO);
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result page(DishPageQueryDTO dto){
        log.info("菜品分页查询:{}", dto);
        return dishService.page(dto);
    }

    /**
     * 删除菜品
     * @return
     */
    @ApiOperation(value = "删除菜品方法")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除菜品:{}", ids);

        return dishService.delete(ids);
    }

    /**
     * 通过id单一查询
     * @return
     */
    @ApiOperation(value = "通过id单一查询方法")
    @GetMapping("/{id}")
    public Result getByid(@PathVariable Long id){
        log.info("根据菜品id查询口味：{}",id);
        return dishService.getByid(id);
    }

    /**
     * 修改菜品
     * @return
     */
    @ApiOperation(value = "修改状态方法")
    @PutMapping
    public Result pudataDish(@RequestBody DishDTO dto){
        log.info("根据菜品id修改菜品：{}",dto);

        return dishService.pudataDish(dto);
    }

    /**
     * 修改出售状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改出售状态方法")
    public Result updateDishStatus(@PathVariable Integer status,Long id){
        log.info("根据菜品id修改出售状态：{}",id);

        return dishService.updateDishStatus(status,id);
    }

    /**
     * CategoryId单一查询
     * @return
     */
    @GetMapping("/list")
    public Result getByCategoryId(Long categoryId){
        return dishService.getByCategoryId(categoryId);
    }
}
